﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
  @*   <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet"> *@
</head>
<body>

    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-inline">
                    
                    
                    <br />
                    <h2>账号信息</h2>
                    <hr class="layui-border-green">
                   
                        <tr>
                            <td>
                                <label class="layui-form-label">账号</label>
                                <div class="layui-input-inline layui-input-wrap">
                                <input type="text" id="userName" name="userName" placeholder="请输入账号" class="layui-input">
                                </div>
                            </td>
                            <td>
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-inline layui-input-wrap">
                                <input type="password" id="userPwd" name="userPwd" placeholder="请输入密码" class="layui-input">
                                </div>
                            </td>
                        </tr>


                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">保存</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>

</html>

<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;

        // 提交事件
        form.on('submit(demo1)', function (data) {
            // var data = {

            //     userName: $("#userName").val(),
            //     userPwd: $("#userPwd").val(),
            // };
             var field = data.field; // 获取表单字段值
                console.log(field) //在控制台显示值
            $.ajax({
                url:'@ViewBag.RBACWrite' + "/api/Users/addUsers",
                type: 'post',
                data: JSON.stringify(field),

                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.msg('添加成功')
                        location.href='User'
                    }
                    else {
                        layer.msg('保存失败')
                    }
                }
            })
            return false; // 阻止默认 form 跳转
        });

    });




</script>


